# -*- coding:utf-8 -*-

'''py3 版本'''

from urllib import request
import re

url='https://movie.douban.com'
baidu = request.urlopen(url)
#获取html源代码(字节)
data=baidu.read()
print(data)
#转化成字符串
html=data.decode('utf-8')
#通过正则表达式筛选出图片
# imglist=re.findall(r'src="(https://.*\.jpg|png)"',html)
imglist=re.findall(r'https://.{1,100}\.jpg|https://.{1,100}\.png|https://.{1,100}\.jpeg',html)
x=0
for img in imglist:
    print(img)
    #通过图片url地址下载到本地
    request.urlretrieve(img,'download/%s.jpg' % x)
    x+=1
    
 
   
''' a: 已经下载的数据块
    b: 数据块的大小
    c: 远程文件的大小
'''
def downloadprocess(a, b, c):
#     print 'a=',a
#     print 'b=',b
#     print 'c=',c
    currentprocess=100.0*a*b/c
    print(currentprocess)
    if currentprocess>=100:
        print('download complete')

